"""Gateway prefix compatibility routes.

Provides /iuap-api-gateway/... paths that map to existing
business endpoints to simulate YonYou production gateway prefix.
"""
from flask import Blueprint

# Import underlying handlers
from app.api.production import (
    get_production_order_list,
    get_production_order_detail,
    production_completion_save,
)
from app.api.inventory import (
    query_current_stocks_by_condition,
    material_outbound_save,
)
from app.api.inspection import (
    get_inspection_list,
    get_inspection_detail,
    save_inspection_order,
)


gateway_bp = Blueprint("gateway", __name__, url_prefix="/iuap-api-gateway")


# MFG - Production
@gateway_bp.route("/yonbip/mfg/productionorder/list", methods=["POST"])
def gw_production_order_list():
    return get_production_order_list()


@gateway_bp.route("/yonbip/mfg/productionorder/detail", methods=["GET"])
def gw_production_order_detail():
    return get_production_order_detail()


@gateway_bp.route("/yonbip/mfg/finishedreport/new/save", methods=["POST"])
def gw_finished_report_save():
    return production_completion_save()


# SCM - Inventory
@gateway_bp.route("/yonbip/scm/stock/QueryCurrentStocksByCondition", methods=["POST"])
def gw_query_current_stocks_by_condition():
    return query_current_stocks_by_condition()


@gateway_bp.route("/yonbip/scm/materialout/mergeSourceData/save", methods=["POST"])
def gw_material_outbound_save():
    return material_outbound_save()


# QMS - Inspection
@gateway_bp.route("/yonbip/QMS_QIT/checkapply/list", methods=["POST"])
def gw_inspection_list():
    return get_inspection_list()


@gateway_bp.route("/yonbip/QMS_QIT/checkapply/detail", methods=["GET"])
def gw_inspection_detail():
    return get_inspection_detail()


@gateway_bp.route("/yonbip/QMS_QIT/inspectorder/save", methods=["POST"])
def gw_save_inspection_order():
    return save_inspection_order()


__all__ = ["gateway_bp"]

